package sort;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;

/**
 * 选择排序
 */
public class SelectSort {
    public static <T extends Comparable> List<T> sort(List<T> nums) {
        List<T> result = new ArrayList<T>(nums);
        int numIdx = -1;
        for (int i = 0; i < result.size(); i++) {
            numIdx = i;
            for (int j = i + 1; j < result.size(); j++) {
                if (result.get(j).compareTo(result.get(numIdx)) < 0) {
                    numIdx = j;
                }
            }
            T tmp = result.get(i);
            result.set(i, result.get(numIdx));
            result.set(numIdx, tmp);
        }
        return result;
    }

}
